/**  
* @Title: PermissionServiceImpl.java  
* @Package com.clps.dev.sms.service.sm.impl  
* @Description: PermissionServiceImpl.java  
* @author RuiShan.Yang  
* @date 2018-11-27 16:06:12 
* @version V1.0  
*/

package com.clps.dev.sms.service.sm.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.clps.dev.sms.common.CommonData;
import com.clps.dev.sms.common.service.impl.BaseServiceImpl;
import com.clps.dev.sms.dao.sm.PermissionDao;
import com.clps.dev.sms.entity.sm.Permission;
import com.clps.dev.sms.service.sm.IPermissionService;

/**  
* @ClassName: PermissionServiceImpl  
* @Description: PermissionServiceImpl  
* @since JDK 1.8 
* @author RuiShan.Yang  
* @date 2018-11-27 16:06:12  
* 
*/
@Service
@Transactional
public class PermissionServiceImpl extends BaseServiceImpl<Permission> implements IPermissionService {
	/**  
	* 创建一个新的实例 PermissionServiceImpl.  
	*
	*/ 
	public PermissionServiceImpl() {
		super(Permission.class);
		// 
	}

	@Autowired
	private PermissionDao permissionDao;

	/**
	* <p>Title: addPermission</p>  
	* <p>Description: </p> 
	* @see com.clps.dev.sms.service.sm.IPermissionService#addPermission(com.clps.dev.sms.entity.sm.Permission)  
	*/
	@Override
	public String addPermission(Permission permission) {
		if ("".equals(permission.getPermissionCreatedEmployeeId() + "") || permission.getPermissionCreatedTime() == null
				|| "".equals(permission.getPermissionUpdatedEmployeeId() + "")) {
			return CommonData.NULL_VALUE_FAILURE;
		}
		int i = permissionDao.save(permission);
		if (i > 0) {
			return CommonData.SAVE_SUCCESS;
		} else {
			return CommonData.SAVE_FAILURE;
		}
	}

	/**
	* <p>Title: deletePermissionById</p>  
	* <p>Description: </p> 
	* @see com.clps.dev.sms.service.sm.IPermissionService#deletePermissionById(java.lang.Integer)  
	*/
	@Override
	public String deletePermissionById(Integer permissionId) {
		Permission permission2 = queryPermissionById(permissionId);
		if (permission2 == null) {
			return CommonData.QUERY_FAILURE;
		}
		int i = permissionDao.deleteById(permissionId);
		if (i > 0) {
			return CommonData.DELETE_SUCCESS;
		} else {
			return CommonData.DELETE_FAILURE;
		}

	}

	/**
	* <p>Title: editPermission</p>  
	* <p>Description: </p> 
	* @see com.clps.dev.sms.service.sm.IPermissionService#editPermission(com.clps.dev.sms.entity.sm.Permission)  
	*/
	@Override
	public String editPermission(Permission permission) {
		if (permission == null) {
			return CommonData.QUERY_FAILURE;
		}
		if (permission.getPermissionCreatedTime() == null) {
			return CommonData.NULL_VALUE_FAILURE;
		}
		int i = permissionDao.update(permission, permission.getPermissionId());
		if (i > 0) {
			return CommonData.UPDATE_SUCCESS;
		} else {
			return CommonData.UPDATE_FAILURE;
		}

	}

	/**
	* <p>Title: queryPermissionById</p>  
	* <p>Description: </p> 
	* @see com.clps.dev.sms.service.sm.IPermissionService#queryPermissionById(java.lang.Integer)  
	*/
	@Override
	public Permission queryPermissionById(Integer permissionId) {
		return permissionDao.queryById(permissionId);
	}

	/**
	* <p>Title: queryPermissionByName</p>  
	* <p>Description: </p> 
	* @see com.clps.dev.sms.service.sm.IPermissionService#queryPermissionByName(java.lang.String)  
	*/
	@Override
	public List<Permission> queryPermissionByName(String permissionName) {
		List<Permission> permissionList = permissionDao.queryPermissionByPermissionLikeName(permissionName);
		return permissionList;
	}

	/**
	* <p>Title: queryAllPermission</p>  
	* <p>Description: </p> 
	* @see com.clps.dev.sms.service.sm.IPermissionService#queryAllPermission()  
	*/
	@Override
	public List<Permission> queryAllPermission() {
		List<Permission> permissionList = permissionDao.queryALl();
		return permissionList;
	}

	/**
	* <p>Title: queryBySql</p>  
	* <p>Description: </p> 
	* @see com.clps.dev.sms.service.sm.IPermissionService#queryPermissionBySql(java.lang.String)  
	*/
	@Override
	public List<Permission> queryPermissionBySql(String sql) {
		List<Permission> permissionList = permissionDao.queryPermissionBySql(sql);
		return permissionList;
	}

}
